﻿using System;

namespace Atha.Clients.ViewModels
{
	public class CommandViewModel : ViewModelBase
	{
		private readonly Action _onClick;

		public CommandViewModel(string text, string smallImagePath)
			: this(text, smallImagePath, smallImagePath)
		{
		}

		public CommandViewModel(string text, string smallImagePath, bool canClick)
			: this(text, smallImagePath, smallImagePath, canClick)
		{
		}

		public CommandViewModel(string text, string smallImagePath, string largeImagePath, bool canClick)
			: this(text, smallImagePath, smallImagePath, canClick, null)
		{
		}

		public CommandViewModel(string text, string smallImagePath, string largeImagePath)
			: this(text, smallImagePath, smallImagePath, true, null)
		{
		}

		public CommandViewModel(string text, string smallImagePath, Action onClick)
			: this(text, smallImagePath, smallImagePath, true, onClick)
		{
		}

		public CommandViewModel(string text, string smallImagePath, bool canClick, Action onClick)
			: this(text, smallImagePath, smallImagePath, canClick, onClick)
		{
		}

		public CommandViewModel(
			string text,
			string smallImagePath,
			string largeImagePath,
			bool canClick,
			Action onClick)
		{
			this._onClick = onClick;
			this.Text = text;
			this.SmallImagePath = smallImagePath;
			this.LargeImagePath = largeImagePath;
			this.ClickCommand = new DelegateCommand(canClick, this.OnClick);
		}

		public event EventHandler<ViewModelEventArgs<CommandViewModel>> Clicked;

		public DelegateCommand ClickCommand { get; private set; }

		public string Text { get; private set; }

		public string SmallImagePath { get; private set; }

		public string LargeImagePath { get; private set; }

		private void OnClick()
		{
			if (this._onClick != null) this._onClick();
			if (this.Clicked != null) this.Clicked(this, new ViewModelEventArgs<CommandViewModel>(this));
		}
	}
}